package com.webtaglib.tags;

import java.io.IOException;

import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class TimeTag extends TagSupport{
	
	private static final long serialVersionUID = -156235916757035040L;
	private long start;
	private long end;
	public int doStartTag(){
		start=System.currentTimeMillis();
		return EVAL_BODY_INCLUDE; //返回一个常量
	}
	//doStartTag()方法在标记开始的时候被调用
	
	public int doEndTag() throws JspTagException{
		end=System.currentTimeMillis();
		long elapsed=end-start;
		try {
			JspWriter out=pageContext.getOut();//pageContext是从TagSupport继承过来的
			out.println("running time:"+elapsed+"ms.");
		} catch (IOException e) {
			throw new JspTagException(e);
		}
		return EVAL_PAGE;
	}
}
